package com.dangz.dans.dao;

import com.dangz.dans.model.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author dangz
 * @since 2018/7/9 11:04
 */
@Repository
public interface MessageRepository extends JpaRepository<Message, Long> {
    List<Message> findAllByToAndStatusOrderByCreateTimeDesc(String to, Integer status);
    @Modifying
    @Transactional
    @Query("update Message set status = ?1 where to = ?2")
    void updateStatusByTo(Integer status, String to);
}
